//
//  FavCell.swift
//  BaseSwift
//
//  Created by gh on 2019/10/5.
//  Copyright © 2019 ghwang. All rights reserved.
//

import UIKit

class FavCell: UITableViewCell {

    let photo = UIImageView()
    let introLab = UILabel()
    let nameLab = UILabel()
    
    
    var tagsView:STTagsView? = nil


    let containerView = UIView()

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        self.contentView.addSubview(containerView)
        self.containerView.sd_cornerRadius = 8
        self.backgroundColor = UIColor.backgroundColor
        containerView.backgroundColor = UIColor.white
        self.selectionStyle = .none

        let _ = containerView.sd_layout()?.spaceToSuperView(UIEdgeInsets(top: 12, left: 12, bottom: 0, right: 12))
        
        containerView.addSubview(photo)
        photo.backgroundColor = UIColor.cccColor
        let _ = photo.sd_layout()?.widthIs(80)!.heightIs(80)!.leftSpaceToView(containerView,16)!.centerYEqualToView(containerView)
        
        containerView.addSubview(nameLab)
        nameLab.font = UIFont.commonFont
        nameLab.textColor = UIColor.textTitleColorBlack
        nameLab.text = "这里是地点名称，太长就用..."
        let _ = nameLab.sd_layout()?.leftSpaceToView(photo,16)!.heightIs(20)!.topSpaceToView(containerView,16)!.rightSpaceToView(containerView,16)
        
        containerView.addSubview(introLab)
        introLab.font = UIFont.smallerFont
        introLab.textColor = UIColor.textPlaceHolderColor
        introLab.text = "此处是地点的特色描述"
        let _ = introLab.sd_layout()?.leftSpaceToView(photo,16)!.heightIs(20)!.topSpaceToView(nameLab,16)!.rightSpaceToView(containerView,16)
        
        introLab.updateLayout()
        containerView.updateLayout()

    }

    func setModel(mod:FavVo){
        
        if tagsView != nil {
            
            tagsView?.removeFromSuperview()
        }
        nameLab.text = mod.pdtName
        introLab.text = mod.pdtDesc
        photo.updateLayout()
        let tags = mod.tags?.split(string: ",")
        tagsView = STTagsView.tagView(withFrame: CGRect(x: 105, y: 112-15-10-23, width: containerView.width-40, height: 15), tagsArray: tags, textColor: UIColor.GP_Blue_Color, textFont: UIFont .systemFont(ofSize: 10), normalTagBackgroundColor: UIColor.backgroundColor, tagBorderColor: UIColor.GP_Blue_Color, contentInsets: UIEdgeInsets(top: 10, left: 5, bottom: 10, right: 5), labelContentInsets: UIEdgeInsets(top: 3, left: 3, bottom: 3, right: 3), labelHorizontalSpacing: 5, labelVerticalSpacing: 5)
        containerView.addSubview(tagsView!)
        
        photo.sd_setImage(with: URL(string:mod.pdtImg!), placeholderImage: UIImage(named: "holder"), options: .lowPriority) { (A, B, C, D) in
            
        }
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
